Skip to content

Merge main-next into main. #636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Aug 22, 2024
Merged

Merge main-next into main. #636

merged 15 commits into from
Aug 22, 2024

Conversation

grynspan
Copy link
Contributor

Now that we've branched for 6.0, the main branch is open for 6.1 development. Merge in previously-reviewed, staged changes.

grynspan and others added 14 commits August 20, 2024 20:16
This PR supersedes #603, #613, and #614. Exit tests remain an
experimental feature.

## Clarify that 8-bit exit codes aren't a problem on macOS and Windows.
(#603)

The documentation for the experimental exit tests feature currently says
that on POSIX-like systems, only the low 8 bits of a process' exit code
are preserved. This would be true if we used `wait()`, `wait4()`, etc.
and `WEXITSTATUS()`, but we use `waitid()` instead which is [supposed
to](https://pubs.opengroup.org/onlinepubs/9699919799/functions/exit.html)
preserve the full exit code. It does so on Darwin, but not on Linux;
Windows doesn't use `waitid()` but does report the full exit code.

Now, we're not currently building for any other POSIX-like systems that
support processes (WASI/Wasm doesn't count here), so I've left in some
weasel words and added a canary unit test. It will let us know if/when
we add a platform that where `waitid()` doesn't preserve all the bits of
the exit code, and we can amend the documentation in that case.

 ## Implement an equality operator for ExitCondition. (#613)

This PR implements `==` and `===` for `ExitCondition`, part of the
experimental exit tests feature. These operators are necessary in order
to allow for exit tests to support more complex matching by trailing
closure (e.g. to support inspecting `stdout`.) Because `.failure` is a
fuzzy case, `==` fuzzy-matches while `===` exactly matches. `Hashable`
conformance is unavailable.

Example usage:

```swift
let lhs: ExitCondition = .failure
let rhs: ExitCondition = .signal(SIGTERM)
print(lhs == rhs) // prints "true"
print(lhs === rhs) // prints "false"
```

 ## Allow throwing an error from an exit test's body. (#614)

This PR amends the signatures of the exit test macros
(`#expect(exitsWith:) {}` and `try #require(exitsWith:) {}`) to allow
bodies to throw errors. If they do, they are treated as uncaught errors
and the child process terminates abnormally (in the same way it does if
an error is thrown from the main function of a Swift program.)

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
This PR enables using move-only types as suites. For example:

```swift
@suite struct NumberOfBeesTests: ~Copyable {
  @test consuming func countBees() {
    var count = 0
    for species in allSpecies {
      if species is Bee {
        count += species.populationCount
      }
    }

    #expect(count > 0)
  }
}
```

Move-only types have a number of constraints in Swift, and those
constraints aren't lifted in a test target, but generally speaking a
move-only type should be able to do all the things any other type can do
_as a test suite_.

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
We no longer define `SWT_BUILDING_WITH_CMAKE`, but one file's still
checking for it. Fix.

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
This PR adds an overload of `try #require()` that warns the developer if
they pass a non-optional, non-`Bool` value For example, this code:

```swift
let x = 0
let y = try #require(x)
```

Will produce the diagnostic:

> ⚠️ '#require(\_:\_:)' is redundant because 'x' never equals 'nil'

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
…`. (#610)

This PR refactors the implementation of `#expect()` and `#require()` a
bit such that they don't incur more than minimal overhead posting
`.expectationChecked` events if nobody is listening for them (which,
currently, nobody is.)

We considered removing `.expectationChecked` outright, but XCTest has
historically had a number of requests for a way to observe calls to
`XCTAssert()` etc. even when they pass, so we opted not to remove the
event kind at this time.

This PR also introduces a cache for fully-qualified type names so that
we don't need to call into the runtime to get them as often.

Overall speedup is approximately **90% or 11x**. Test time for a tight
loop of 1,000,000 `#expect()` calls goes from 5.898893 seconds down to
0.515558291 seconds (as measured on my work computer.)

Resolves rdar://133517028.

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
…ge. (#598)

Unbounded ranges are not meaningful when used with `confirmation()`
because _any_ confirmation count matches. As well, the `...` operator
produces an instance of `UnboundedRange` which is a non-nominal type and
cannot conform to `RangeExpression`. It may be non-obvious to a
developer why `...` doesn't work as the `expectedCount` argument to that
function when other range operators work as expected.

This PR implements a stub overload of `confirmation()` that takes an
unbounded range. The stub overload is marked unavailable and cannot be
called.

Example usage:

```swift
await confirmation("Stuff happens", expectedCount: ...) { stuff in
  // ...
}
```

Generated diagnostic:

> 🛑 'confirmation(\_:expectedCount:sourceLocation:\_:)' is unavailable:
Unbounded range '...' has no effect when used with a confirmation.

As a reminder, using a range expression with `confirmation()` is an
experimental feature and has not been API-reviewed.

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
This PR fixes a conflict between #610 and #619. #610 added a string
cache to `TypeInfo` using `ObjectIdentifier` instances as keys. #619
added support for move-only types to `TypeInfo`. Due to
rdar://134276458, move-only types cannot be used with
`ObjectIdentifier`. This PR uses `UInt` instead until that issue can be
resolved in a future stdlib update.

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
Android recommends `clock_gettime` over `timespec_get` which is
available at Level 29 and newer. This is needed to build swift-testing
for Android.
Testing: use `clock_gettime` on Android
This PR adds a diagnostic if we detect that `@Test` has been used on a
member function of an `XCTestCase` subclass. This was meant to be
disallowed, but we neglected to add a check after adopting
`lexicalContext`.

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
This PR adds 100% test coverage to CustomTestStringConvertible.swift.

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
Add some force unwraps to address nullability differences on Android
from other platforms.
Testing: add some force unwraps for Android
@grynspan
Copy link
Contributor Author

@swift-ci test

…it tests. (#635)

On platforms without exit tests, `ExitCondition` is marked unavailable.
On those platforms, the new operators on `ExitCondition` call each other
and the compiler complains because they're calling unavailable symbols.
Silence the compiler.

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan merged commit 03c6518 into main Aug 22, 2024
3 checks passed
@grynspan grynspan deleted the main-next branch August 22, 2024 13:39
@grynspan grynspan added this to the Swift 6.1 milestone Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants